/* 
 * Shuriken is the legal property of its developers. Please refer to the
 * COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


using System;
using System.Collections.Generic;
using System.Text;
using Shuriken.Base;

namespace Shuriken.Core.Store
{
    /// <summary>
    /// Sorted list to handle actions
    /// </summary>
    public class ActionList : SortedDisplayItemList 
    {
        private static bool FindDefaultAction(ISearchable item)
        {
            if (!(item is IAction))
            {
                return false; 
            }

            return ((IAction)item).IsDefault; 
        }

        /// <summary>
        /// Returns the index of default action 
        /// </summary>
        /// <returns>index of default index</returns>
        public int DefaultActionIndex
        {
            get
            {
                int index = FindIndex(FindDefaultAction);

                if (index == -1 && Count > 0)
                {
                    index = 0; 
                }

                return index;
            }
        }

        /// <summary>
        /// Adds an object to the end of the collection. 
        /// </summary>
        /// <param name="action">Action to add</param>
        public void Add(IAction action)
        {
            base.Add((ISearchable)action);
        }

        /// <summary>
        /// Adds the elements of the specified collection to the end of this collection.
        /// </summary>
        /// <param name="actions">actions</param>
        public void AddRange(IEnumerable<IAction> actions)
        {
            foreach (IAction action in actions)
            {
                Add(action);
            }
        }
    }
}
